/**
 * 核心接口定义
 */

import type { 
  HistoryVersion, 
  VersionEntries, 
  FileHistoryRecord
} from './history'
import type { 
  FileStats, 
  CopyOperation, 
  BatchResult 
} from './file-operations'
import type { 
  RecoveryOptions,
  RecoveryTask,
  RecoveryResult,
  BatchRecoveryOptions,
  BatchRecoveryResult,
  RecoveryPreview
} from './recovery'
import type { 
  SearchOptions,
  ContentSearchOptions,
  SearchResult,
  ContentSearchResult,
  SearchCriteria
} from './search'

// 历史解析器接口
export interface HistoryParser {
  // 扫描History目录获取所有版本
  scanHistoryVersions(): Promise<HistoryVersion[]>
  
  // 解析特定版本的entries.json
  parseVersionEntries(versionId: string): Promise<VersionEntries>
  
  // 获取文件的历史记录
  getFileHistory(filePath: string): Promise<FileHistoryRecord[]>
  
  // 获取版本中的文件内容
  getFileContent(versionId: string, fileId: string): Promise<string>
  
  // 获取文件统计信息
  getFileStats(versionId: string, fileId: string): Promise<{
    size: number
    modifiedTime: Date
    isDirectory: boolean
    exists: boolean
  }>
  
  // 获取版本中的所有文件
  getVersionFiles(versionId: string): Promise<string[]>
}

// 文件操作接口
export interface FileOperations {
  // 读取文件内容
  readFile(filePath: string): Promise<string>
  
  // 写入文件
  writeFile(filePath: string, content: string): Promise<void>
  
  // 复制文件
  copyFile(sourcePath: string, targetPath: string): Promise<void>
  
  // 创建目录
  ensureDirectory(dirPath: string): Promise<void>
  
  // 检查文件是否存在
  fileExists(filePath: string): Promise<boolean>
  
  // 获取文件统计信息
  getFileStats(filePath: string): Promise<FileStats>
  
  // 批量复制文件
  batchCopyFiles(operations: CopyOperation[]): Promise<BatchResult>
}

// 恢复引擎接口
export interface RecoveryEngine {
  // 恢复单个文件
  recoverFile(
    versionId: string, 
    fileId: string, 
    targetPath: string, 
    options: RecoveryOptions
  ): Promise<RecoveryResult>
  
  // 批量恢复文件
  batchRecover(
    recoveryTasks: RecoveryTask[], 
    options: BatchRecoveryOptions
  ): Promise<BatchRecoveryResult>
  
  // 预览恢复操作
  previewRecovery(tasks: RecoveryTask[]): Promise<RecoveryPreview>
}

// 搜索引擎接口
export interface SearchEngine {
  // 按文件名搜索
  searchByFileName(query: string, options: SearchOptions): Promise<SearchResult[]>
  
  // 按文件内容搜索
  searchByContent(query: string, options: ContentSearchOptions): Promise<ContentSearchResult[]>
  
  // 高级搜索
  advancedSearch(criteria: SearchCriteria): Promise<SearchResult[]>
  
  // 建立搜索索引
  buildIndex(): Promise<void>
}